﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLoginLayer
{
    public partial class Flights
    {
        public static CommonClasses.Flight GetFlightByID(string Id)
        {
            using (PlanesManagerEntity entity = new PlanesManagerEntity())
            {
                return (from ent in entity.GetFlightByID(Id)
                        select new CommonClasses.Flight()
                        {
                            ArriveDate = ent.Arrival_Date,
                            DepartureDate = ent.Departure_Date,
                            Destination = ent.Destination,
                            Id = ent.ID,
                            Lotation = ent.Lotation,
                            Origin = ent.Origin,
                            TotalReservations = ent.Reservations.Value,
                            Price = ent.SeatPrice,
                            
                        }).FirstOrDefault();
            }
        }

        public static CommonClasses.Flight[] GetFlightByQuery(DateTime BeginDate, DateTime? EndDate, double? PriceLimit, string Origin, string Destination)
        {
            using (PlanesManagerEntity entity = new PlanesManagerEntity())
            {
                return (from ent in entity.QueryFlights(BeginDate, EndDate, PriceLimit, Origin, Destination)
                        select new CommonClasses.Flight()
                        {
                            ArriveDate = ent.Arrival_Date,
                            DepartureDate = ent.Departure_Date,
                            Destination = ent.Destination,
                            Id = ent.ID,
                            Lotation = ent.Lotation,
                            Origin = ent.Origin,
                            TotalReservations = ent.totalBookings,
                            Price = ent.SeatPrice,
                        }).ToArray();
            }
        }

    }
}
